package com.zz.parkingsystem.controller.admin;

import com.zz.parkingsystem.entity.Checkon;
import com.zz.parkingsystem.entity.Inspector;
import com.zz.parkingsystem.service.CheckOnService;
import com.zz.parkingsystem.service.InspectorService;
import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 已测staCheckOn(list返回结果集街区name和巡检name为null？？？？？？？？？)
 */
@RestController
@RequestMapping("/admin/check")
public class AdminCheckController {
    @Resource
    private CheckOnService checkOnService;
    @Resource
    private InspectorService inspectorService;
    //考勤统计()
    @RequestMapping("/staCheckOn")
    public Result staCheckOn(@RequestParam(value = "co_time",required = false)String co_time){
        //巡检员总数 (返回前端)
        int sum = inspectorService.getselAllsum();
        System.out.println(sum+"巡检员总数===================================");
        //集合包含列(巡检名，执行街道名称，正常天数，迟到天数即异常天数)返回前端
        List list = checkOnService.getselstaCheckOn(co_time);
        System.out.println(list+"list===================================");
        //正常打卡数
        int i1 = checkOnService.getselnormal();
        System.out.println(i1 +"正常打卡数===================================");
        //异常打卡数
        int i2 = checkOnService.getselAbnormal();
        System.out.println(i2 +"异常打卡数===================================");
        //正常率  (返回前端)
        double i3=i1/(i1+i2);
        //==================================================================
        // 创建一个数值格式化对象
        NumberFormat numberFormat = NumberFormat.getInstance();
        // 设置精确到小数点后2位
        numberFormat.setMaximumFractionDigits(2);
        String result = numberFormat.format((float)i1/(float)(i1+i2)*100);
        System.out.println("正常率百分比为:" + result + "%");
        //===================================================================
        Map<String, Object> map =new HashMap<>();
        map.put("sum",sum);
        map.put("list",list);
        map.put("i3",i3);
        return ResultGenerator.genSuccessResult(map);
    }
}
